<script type="text/javascript">
function toggle(controlId)
{
	var control = document.getElementById("add");
	control.style.display = "none";
	control = document.getElementById("edit");
	control.style.display = "none";
	control = document.getElementById("addPhoto");
	control.style.display = "none";
	control = document.getElementById(controlId);
	control.style.display = "block";
}
</script>

<?php if(!$_SESSION['category']->getUserId()){?>
<a href="category.php?up=true"><img src="images/previous.png" width="150"/></a><br/>
<?php } ?>
<input type="button" id="btnToggleAdd" value="Add category" onclick="toggle('add');" />
<input type="button" id="btnToggleEdit" value="Edit category" onclick="toggle('edit');" />
<input type="button" id="btnToggleAddPhoto" value="Add Photo" onclick="toggle('addPhoto');" />

<form id="edit" action="category.php" method="post">
	<div class="fieldset">
		<div class="legend">Category details: </div>
		<a class="label">Name</a><input type="text" name="name" value="<?php print $_SESSION['category']->getName(); ?>"/>
		<button name="edit_btn">Edit!</button>
<?php if(!$_SESSION['category']->getUserId()){?>
		<button name="delete_btn">Delete!</button>
<?php } ?>
	</div>
</form>

<form id="add" action="category.php" method="post">
	<div class="fieldset">
		<div class="legend">Add category: </div>
		<a class="label">Name</a><input type="text" name="name"/>
		<button name="add_category_btn">Add!</button>
	</div>
</form>
<form id="addPhoto" action="category.php" method="post" enctype="multipart/form-data">
	<div class="fieldset">
		<div class="legend">Add photo: </div>
		<a class="label">Photo</a><input type="file" name="data" id="data"/><br/>
		<a class="label">Name</a><input type="text" name="name"/><br/>
		<a class="label">Description</a><input type="text" name="description"/><br/>
		<button name="add_photo_btn">Add!</button>
	</div>
</form>

<?php
$categories = $_SESSION['category']->getCategories();
if(count($categories) != 0)
{
?>
<h1 class="category"><em><?php print ($_SESSION['category']->getName());?> Categories</em></h1>
<ul class="gallery">
<?php
foreach ($categories as $category)
{
?>
<li>
	<a href="category.php?category_id=<?php print $category->getCategoryId(); ?>">
		<span></span><em><?php print $category->getName(); ?></em>
		<img src="images/folder.png" alt="<?php print $category->getName(); ?>" width="100"/>
	</a>
</li>
<?php
}
?>
</ul>
<div class="cleaner"></div>
<?php
}
?>

<h1 class="category"><em><?php print ($_SESSION['category']->getName());?> Photos</em></h1>
<ul class="gallery">
<?php
$photos = $_SESSION['category']->getPhotos();
foreach ($photos as $photo)
{
?>
<li>
	<a href="photo.php?photo_id=<?php print $photo->getPhotoId(); ?>">
		<span></span><em><?php print $photo->getName(); ?></em>
		<img src="<?php print $photo->getFilename(); ?>" alt="<?php print $photo->getName(); ?>" width="150"/>
	</a>
</li>
<?php
} 
?>
</ul>

<div class="cleaner"></div>
